package com.tbit.main.controller;

import com.tbit.main.common.JsonResult;
import com.tbit.main.constant.MapConstant;
import com.tbit.main.pojo.AccountUser;
import com.tbit.main.pojo.ParkPointApply;
import com.tbit.main.service.ParkPointApplyService;
import com.tbit.main.service.TokenService;
import com.tbit.main.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 站点审核
 *
 * @author LMY
 * @create 2022-07-05 15:45
 */
@RestController
@RequestMapping("/parkPointApply")
public class ParkPointApplyController {

    @Autowired
    private ParkPointApplyService parkPointApplyService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询
     *
     * @param token
     * @param phone     申请人手机号
     * @param accountId 区域id
     * @param lon       经度
     * @param lat       纬度
     * @param radius    范围 单位米
     * @param mapType   地图类型
     * @return ParkPointApply
     */
    @RequestMapping("/getAccountId")
    public JsonResult<List<ParkPointApply>> getAccountId(@NotNull String token, String phone, @NotNull Integer accountId,
                                                         Double lon, Double lat, Integer radius, Integer mapType) {

        /* 校验 */
        Assert.notNull(accountId, "AccountUser.agentId.notNull");
        if (radius != null) {
            Assert.notNull(lon, "System.lon.notNull");
            Assert.notNull(lat, "System.lat.notNull");
            if (mapType == null) {
                mapType = MapConstant.MAP_GOOGLE;
            }
        }

        List<ParkPointApply> parkPointApplyList = parkPointApplyService.getByAccountId(phone, accountId, lon, lat, radius, mapType);

        return JsonResult.succ(parkPointApplyList);
    }

    /**
     * 审核
     *
     * @param token
     * @param parkPointApplyId 审核id列表
     * @param state            审核状态：0不通过，1通过
     * @param handleInfo       审核理由
     * @return null
     */
    @RequestMapping("/audit")
    public JsonResult audit(String token, @NotNull @RequestParam(value = "parkPointApplyId", required = true) List<Integer> parkPointApplyId,
                            @NotNull Integer state, @NotNull String handleInfo) {

        AccountUser accountUser = tokenService.getAccount(token);

        parkPointApplyService.audit(accountUser.getAccountUserId(), parkPointApplyId, state, handleInfo);

        return JsonResult.succ();
    }

}
